﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Dropit.BlogPageProvider
{
	public static class StringExtensions
	{
		public static string Shorten(this string str, int maxLength)
		{
			return str.Shorten(maxLength, "...");
		}

		public static string Shorten(this string str, int maxLength, string overflow)
		{
			if (string.IsNullOrEmpty(str) || str.Length <= maxLength)
			{
				return str;
			}
			return string.Concat(str.Substring(0, maxLength), overflow);
		}

		public static string HtmlDecode(this string str)
		{
			if (HttpContext.Current != null)
			{
				return HttpContext.Current.Server.HtmlDecode(str);
			}
			return null;
		}
	}
}
